package guoanmaker.operator.business.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.InRoundPhone;

import guoanmaker.operator.business.model.OperatorPcActive;
import guoanmaker.operator.business.service.OperatorPcActiveServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
/**
 * 活动首页显示--官网线下活动
* @ClassName: OperatorPcActiveController
* @Description:TODO (这里用一句话描述这个类的作用) 
* @author lihongyu
* @date 2017年9月4日 下午10:15:13 
*  
 */
@RestController
@RequestMapping(ApiController.OPERATOR_PC_ACTIVE)
public class OperatorPcActiveController {
	@Autowired
	private OperatorPcActiveServiceInterface operatorPcActiveServiceInterface;
	 @ApiOperation(value = "保存活动首页显示", notes = "新增/修改活动首页显示")
	    @PostMapping(value = "saveOperatorPcActiver")
	    public AjaxJson saveOperatorPcActive(@RequestBody InRoundPhone inRoundPhone) {
		 AjaxJson ajaxJson=new AjaxJson();
		 try{
	    		OperatorPcActive[] OperatorPcActives=inRoundPhone.getOperatorPcActives();
	    	
	    		operatorPcActiveServiceInterface.delectAllBycitycode(inRoundPhone.getCityId());
	    	for(OperatorPcActive hotserver:OperatorPcActives){
	    		/*if(null!=hotserver.getId()&&!hotserver.getId().equals("")){
	    			operatorPcActiveServiceInterface.deleteOperatorPcActive(hotserver.getId());
	    		}*/
	    		hotserver.setCityId(inRoundPhone.getCityId());
	    		hotserver.setCreateDate(new Date());
	    		operatorPcActiveServiceInterface.saveOperatorPcActive(hotserver);
	    	}
	    	ajaxJson.setSuccess(true).setStatus(200).setData(null);
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		ajaxJson.setSuccess(false).setStatus(250).setData(null);
	    	}
	        return ajaxJson;
	    }
	 
	 
	 @ApiOperation(value = "查询线下活动列表", notes = "查询线下活动列表")
	    @PostMapping(value = "getAllOperatorPcActive")
	    public AjaxJson getAllOperatorPcActive(String cityId) {
		 AjaxJson ajaxJson=new AjaxJson();
	    	try{
	    	List<OperatorPcActive> hotservers=operatorPcActiveServiceInterface.selectOperatorPcActiveList(cityId);
	    	
	    		ajaxJson.setSuccess(true).setStatus(200).setData(hotservers);
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		ajaxJson.setSuccess(true).setStatus(250).setData(null);
	    	}
	        return ajaxJson;
	    }
}
